package reflect;

import java.io.File;
import java.net.URISyntaxException;


public class Text3 {
    public static void main(String[] args) throws URISyntaxException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        /*
            自动实例化当前类所在包中所有类的实例并输出
         */

        File file = new File(Text3.class.getResource(".").toURI());

        File[] files = file.listFiles(e->e.getName().endsWith(".class"));
        System.out.println(files.length);

        for(File file1 : files){
            String strName = file1.getName();
            String className = strName.substring(0,strName.indexOf("."));
            Class cls = Class.forName("reflect."+className);
            Object o = cls.newInstance();
            System.out.println(o);
        }
    }
}
